package com.huilian.iotbox.mqtt.server.base.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * MQConfig
 * 延迟队列配置器
 *
 * @Author mineChen
 * @Date 2021/3/23 21:15
 */
@Configuration
public class DelayMQConfig {

    /**
     * 延迟消息交换机
     */
    public static final String IOT_BOX_MQTT_LAZY_EXCHANGE = "iotBox.mqtt_lazy_exchange";
    /**
     * 延迟队列
     */
    public static final String IOT_BOX_MQTT_LAZY_QUEUE = "iotBox_mqtt_lazy_queue";
    /**
     * 延迟队列路由key
     */
    public static final String BOX_MQTT_LAZY_QUEUE_KEY = "iotBox.mqtt_lazy_queue";

    /**
     * 延迟消息交换机
     */
    public static final String IOT_BOX_CLIENT_LAZY_EXCHANGE = "iotBox.client_lazy_exchange";
    /**
     * 延迟队列路由key
     */
    public static final String BOX_CLIENT_LAZY_QUEUE_KEY = "iotBox.client_lazy_queue";

    /**
     * 售货机延迟队列路由key
     */
    public static final String BOX_CLIENT_vending_machine_LAZY_QUEUE_KEY = "iotBox.client_vending_machine_lazy_queue";


    // 延迟队列路由key-劵码核销key
    public static final String IOT_BOX_CLIENT_VERIFY_UP_COIN_KEY = "iot-box-client-verify-up-coin";

    /**
     * 拍照机启动延迟队列路由key
     */
    public static final String IOT_BOX_CLIENT_CAMERA_START_LAZY_QUEUE_KEY = "iot_box_client_camera_start_lazy_queue_key";
    /**
     * 延迟发送按摩垫启动指令.延迟队列路由key
     */
    public static final String IOT_BOX_COUCH_FOR_MASSAGE_START_LAZY_QUEUE_KEY = "iot_box_couch_for_massage_start_lazy_queue_key";

    @Bean
    public TopicExchange iotBoxMqttLazyExchange() {
        Map<String, Object> pros = new HashMap<>();
        //设置交换机支持延迟消息推送
        pros.put("x-delayed-message", "topic");
        TopicExchange exchange = new TopicExchange(IOT_BOX_MQTT_LAZY_EXCHANGE, true, false, pros);
        exchange.setDelayed(true);
        return exchange;
    }

    @Bean
    public Queue iotBoxMqttLazyQueue() {
        return new Queue(IOT_BOX_MQTT_LAZY_QUEUE, true);
    }

    @Bean
    public Binding iotBoxAdminLazyBinding() {
        return BindingBuilder.bind(iotBoxMqttLazyQueue()).to(iotBoxMqttLazyExchange()).with(BOX_MQTT_LAZY_QUEUE_KEY);
    }

}
